﻿#pragma once
#include "Common.h"
#include "ObjectPool.h"
class PageCache
{
public:
	static PageCache* GetInstance()
	{
		return &_Instance;
	}
	// 获取⼀个K⻚的span
	Span* NewSpan(size_t k);
	// 获取从对象到span的映射
	Span* MapObjectToSpan(void* obj);

	// 释放空闲span回到Pagecache，并合并相邻的span
	void ReleaseSpanToPageCache(Span* span);
private:
	PageCache() {}
	PageCache(const PageCache&) = delete;
	PageCache& operator=(const PageCache&) = delete;
	SpanList _spanLists[NPAGES];
	static PageCache _Instance;
	std::unordered_map<PAGE_ID, Span*> _IdSpanMap;
	ObjectPool<Span> _spanPool;
public:
	std::mutex _mutex;

};
